using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using System.Configuration.Provider;
using System.Configuration;

namespace CodeFx.MySqlProviders
{
    /// <summary>
    /// Share the MySqlProvider Connection String
    /// </summary>
    internal class ConnectionString
    {
        private static ConnectionString current;
        private string connectionstring;

        private ConnectionString()
        {
        }

        public static ConnectionString Current
        {
            get
            {
                if (current == null)
                {
                    current = new ConnectionString();
                }

                return current;
            }
        }
        
        public MySqlConnection OpenConnection
        {
            get
            {
                ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[connectionStringName];
                if (ConnectionStringSettings == null || ConnectionStringSettings.ConnectionString.Trim().Length == 0)
                    throw new ProviderException("Connection string cannot be blank.");
                MySqlConnection conn = new MySqlConnection(ConnectionStringSettings.ConnectionString);

                conn.Open();
                return conn;
            }
        }

        private string connectionStringName;

        public string ConnectionStringName
        {
            get { return connectionStringName; }
            set { connectionStringName = value; }
        }

    }
 
}
